<%@ page language="java" pageEncoding="utf-8"%>
<%@taglib uri="/WEB-INF/page-base.tld" prefix="w"%>
<%String path=request.getContextPath(); %>

<style type="text/css">

  .gridly
  {
    position: relative;
    display: block;
  }
  .brickpic{border:1px solid #E4E4E4;
   width: 60px;
   cursor:pointer;
    height: 60px;
    -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box; }
  .brickpic img{width:58px;height:58px;}
</style>
<w:define bind="bean.classid" id="classid"/><%if(classid==null)classid=""; %>
<w:hidden bind="bean.id"/>
<w:hidden bind="bean.classid" name="inclassid"/>
<w:hidden bind="bean.details"/>
<w:hidden bind="bean.shuombook"/>
<w:hidden bind="bean.aboutus"/>
<div class="easyui-tabs" id="pedit_tabs" data-options="fit:true,border:false,tools:'#productedittool'">
	<div title="商品信息" class="ui-formContent">
		<!-- 商品信息 -->
		<div style="padding:0 30px 30px 30px">
			<div class="headT"><span></span><label>商品信息</label></div>
			<table width="100%" cellpadding="0" cellspacing="0">
				<tr>
					<td class="label" width="100">商品分类：</td>
					<td class="val">
							<select id="classtree2" name="bean.classid" class="easyui-combotree" style="width:300px;height:28px;" data-options="url:'<%=path %>/products/ProductClassPage@loadClassTree.page',onSelect:clscodechange"></select>
					</td>
				</tr>
				<tr><td class="line8"></td></tr>
				<tr>
					<td class="label">商品名称：</td>
					<td class="val"><w:text bind="bean.name" disabled="true" style="width:300px;" styleClass="beanval easyui-validatebox" dataOptions="required:true"/></td>
				</tr>
				<tr><td class="line8"></td></tr>
				<tr>
					<td class="label">商品编码：</td>
					<td class="val"><w:text bind="bean.code" disabled="true" readonly="true" style="width:300px;" styleClass="beanval"/></td>
				</tr>
				<tr><td class="line8"></td></tr>
				<tr>
					<td class="label">商品单位：</td>
					<td class="val"><select name="bean.unit" disabled="true" style="width:300px;height:30px;" class="beanval"><option value=""></option><w:options bind="bean.unit" dict="ProductUnit"/></select></td>
				</tr>
				<w:iterate id="info" bind="#base_attrs">
					<w:define id="attrid" bind="#info.id"/>
					<w:define id="type" bind="#info.type"/>
					<tr><td class="line8"></td></tr>
					<tr>
						<td class="label"><w:write bind="#info.name"/>：</td>
						<td class="val pattr" id="attrs_<%=attrid %>" attrtype="<w:write bind="#info.type"/>">
							<w:switch>
								<w:case bind="#type.toString().equals('1')"><input disabled="true" value="<w:write bind="#info.val"/>" name="bean.attrs_<%=attrid %>" style="width:300px;"/></w:case>
								<w:case bind="#type.toString().equals('2')">
									<select name="bean.attrs_<%=attrid %>" class="pitem_sel" disabled="true" style="width:300px;height:30px;"><option value=""></option><w:iterate id="item" bind="#info.itemlist"><option value="<w:write bind="#item.code"/>" <w:equal bind="#item.selected" value="true">selected</w:equal>><w:write bind="#item.text"/></option></w:iterate></select>
								</w:case>
							</w:switch>
						</td>
					</tr>
				</w:iterate>
			</table>
			
			<div class="line8"></div>
			<div class="headT"><span></span><label>商品属性</label></div>
			<div class="card_body">
				<table width="100%" cellpadding="0" cellspacing="0">
					<w:iterate id="info" bind="#comm_attrs">
						<w:define id="attrid" bind="#info.id"/>
						<w:define id="type" bind="#info.type"/>
						<tr><td class="line8"></td></tr>
						<tr>
							<td class="label" width="100"><w:write bind="#info.name"/>：</td>
							<td class="val pattr" id="attrs_<%=attrid %>" attrtype="<w:write bind="#info.type"/>">
								<w:switch>
									<w:case bind="#type.toString().equals('1')"><input value="<w:write bind="#info.val"/>" name="bean.attrs_<%=attrid %>" style="width:300px;"/></w:case>
									<w:case bind="#type.toString().equals('2')">
										<select name="bean.attrs_<%=attrid %>" class="pitem_sel" style="height:30px;"><option value=""></option><w:iterate id="item" bind="#info.itemlist"><option value="<w:write bind="#item.code"/>" <w:equal bind="#item.selected" value="true">selected</w:equal>><w:write bind="#item.text"/></option></w:iterate></select>
									</w:case>
									<w:case bind="#type.toString().equals('3')">
										<w:iterate id="item" bind="#info.itemlist">
											<label><input name="bean.attrs_<%=attrid %>" type="checkbox" value="<w:write bind="#item.code"/>" <w:equal bind="#item.selected" value="true">checked</w:equal>><w:write bind="#item.text"/></label>
										</w:iterate>
									</w:case>
									<w:else>&nbsp;</w:else>
								</w:switch>
							</td>
						</tr>
					</w:iterate>
				</table>
			</div>
			
			<div class="line10"></div>
			<div class="headT"><span></span><label>销售属性</label></div>
			<div class="card_body" id="saleattrspanel">
				<input name="sale_attrslen" value="<w:write bind="#sale_attrs.size()"/>" type="hidden">
				<table width="100%" cellpadding="0" cellspacing="0">
					<w:iterate id="info" bind="#sale_attrs">
						<w:define id="attrid" bind="#info.id"/>
						<w:define id="type" bind="#info.type" />
						<tr><td class="line8"></td></tr>
						<tr>
							<td class="label" width="100"><w:write bind="#info.name"/>：</td>
							<td class="val saleattr" id="attrs_<%=attrid %>" attrtype="<w:write bind="#info.type"/>">
								<w:switch>
									<w:case bind="#type.toString().equals('1')"><w:text bind="#info.val" name="bean.attrs_<%=attrid %>" style="width:300px;"/></w:case>
									<w:case bind="#type.toString().equals('2')">
										<select name="bean.attrs_<%=attrid %>" class="pitem_sel" style="height:30px;"><option value=""></option><w:iterate id="item" bind="#info.itemlist"><option value="<w:write bind="#item.code"/>" <w:equal bind="#item.selected" value="true">selected</w:equal>><w:write bind="#item.text"/></option></w:iterate></select>
									</w:case>
									<w:case bind="#type.toString().equals('3')">
										<w:iterate id="item" bind="#info.itemlist">
											<label><input name="bean.attrs_<%=attrid %>" type="checkbox" value="<w:write bind="#item.code"/>" <w:equal bind="#item.selected" value="true">checked</w:equal>><w:write bind="#item.text"/></label>
										</w:iterate>
									</w:case>
									<w:else>&nbsp;</w:else>
								</w:switch>
							</td>
						</tr>
					</w:iterate>
					<w:switch>
					<w:case bind="#sale_attrs.size()>0">
						<tr><td class="line8"></td></tr>
						<tr>
							<td></td><td><a href="javascript:pedit_addsale();" class="easyui-linkbutton">加入销售列表</a></td>
						</tr>
					</w:case>
					</w:switch>
				</table>
				<div class="line8"></div>
				<div class="line8"></div>
				<table width="760" align="center" cellpadding="1" cellspacing="1" id="saleattrstb" style="margin-left:30px;background:#dddddd">
					<tr style="background: #ffffff">
						<td align="center" height="30">销售属性</td>
						<td align="center" width="100">市场价（元）</td>
						<td align="center" width="100">促销价（元）</td>
						<td align="center" width="100">库存</td>
						<td align="center" width="100">冻结库存</td>
						<td align="center" width="50">删除</td>
					</tr>
				</table>
			</div>
			
			<div class="line10"></div>
			<div class="headT"><span></span><label>商品图片<font style="color:red">（提示：拖动图片可进行排序）</font></label></div>
			<div class="card_body" >
				<div class="line8"></div>
				<table width="760" cellpadding="1" cellspacing="1" id="pedit_imgtb" style="margin-left:30px;background:#dddddd">
					
				</table>			
			</div>
			
		</div>
		<!-- 商品信息end -->
	</div>
	<div title="商品详情" class="ui-formContent">
		<input type="button" onclick="synPhoto();" value="同步商品图片"/>
		<div style="margin:15px 30px 0">
			<textarea name="details_content" style="width:730px;height:400px;visibility:hidden;"><w:write bind="bean.details"/></textarea>
		</div>
		<div class="line10"></div>
	</div>
	<div title="说明书" class="ui-formContent">
		<div style="margin:15px 30px 0">
			<textarea name="book_content" style="width:730px;height:400px;visibility:hidden;"><w:write bind="bean.shuombook"/></textarea>
		</div>
		<div class="line10"></div>
	</div>
	<div title="关于我们" class="ui-formContent">
		<div style="margin:15px 30px 0">
			<textarea name="aboutus_content" style="width:730px;height:400px;visibility:hidden;"><w:write bind="bean.aboutus"/></textarea>
		</div>
		<div class="line10"></div>
	</div>
	<div title="控销" class="ui-formContent">
		<div class="line10"></div>
		<table width="100%" cellpadding="0" cellspacing="0">
			<tr>
				<td class="label" width="130" valign="top">分组控销：</td>
				<td class="val">
					<select name="controlsales" id="controlsales" style="width:400px;height:200px;border:1px solid #DDDDDD" multiple="multiple">
					<w:iterate id="info" bind="#controlsales">
						<option value="{'type':'<w:write bind="#info.type"/>','val':'<w:write bind="#info.val"/>','text':'<w:write bind="#info.text"/>'}"><w:write bind="#info.text"/></option>
					</w:iterate>
					</select>
					<div style="margin-top:8px;">
						<a href="javascript:void(0);" class="ui_btn marginR8" onclick="addControlsales()">新增控销</a><a href="javascript:void(0);" class="ui_btn marginR8" onclick="delControlsales()">删除控销</a>
					</div>
				</td>
			</tr>
			<tr><td class="line8"></td></tr>
			<tr><td class="line8"></td></tr>
			<tr><td class="line8"></td></tr>
			<tr><td class="line8"></td></tr>
			<tr>
				<td class="label" valign="top">自定义用户：</td>
				<td class="val">
					<div><a href="javascript:void(0);" class="ui_btn marginR8" onclick="addControlUser()">+添加用户</a></div>
					<div class="line8"></div>
					<table class="ui-table" width="800" cellpadding="1" cellspacing="1" data-options="showPage:false">
						<thead>
							<tr class="ui_th">
								<td width="50" align="center">ID</td>
								<td width="110" align="center">昵称</td>
								<td width="110" align="center">账号</td>
								<td>单位名称</td>
								<td width="100" align="center">客户等级</td>
								<td width="70" align="center">操作</td>
							</tr>
						</thead>
						<tbody id="controlusertb">
						<w:iterate id="info" bind="#controlUsers">
							<tr class="ui_td">
							<td align="center"><input name="controluserid" type="hidden" value="<w:write bind="#info.id"/>"><w:write bind="#info.id"/></td>
							<td align="center"><w:write bind="#info.nickname"/></td>
							<td align="center"><w:write bind="#info.loginname"/></td>
							<td><w:write bind="#info.comname"/></td>
							<td align="center"><w:write bind="#info.grade" dict="UserGrade"/></td>
							<td align="center"><a href="javascript:;" class="ui_btn_link" onclick="delcontroluser(this)">删除</a></td>
							</tr>
						</w:iterate>
						</tbody>
					</table>
				</td>
			</tr>
			<tr><td class="line8"></td></tr>
			<tr><td class="line8"></td></tr>
			<tr><td class="line8"></td></tr>
			<tr><td class="line8"></td></tr>
		</table>
	</div>
	<div title="价格等级设置" class="ui-formContent" style="padding-left:70px;padding-top:10px;">
		<table cellspacing="1" cellpadding="1" style="background-color:#ddd">
			<tr class="ui-formContent">
				<td align="center" width="50" height="24">ID</td>
				<td align="center" width="180">价格等级</td>
				<td align="center" width="80">价格(元)</td>
			</tr>
			<w:iterate id="info" bind="#priceGrades">
				<tr class="ui-formContent">
					<td align="center" height="24"><w:write bind="#info.value"/></td>
					<td align="center"><w:write bind="#info.text"/></td>
					<td align="center"><input name="gradeprice" grade="<w:write bind="#info.value"/>" onkeyup="inputMonery(this)" disabled="true" value="<w:write bind="#info.price"/>"></td>
				</tr>
			</w:iterate>
		</table>
	</div>
	
</div>
<div id="productedittool">
	<w:notEqual bind="bean.edit" value="false"><a href="javascript:pedit_uploaddata();" class="easyui-linkbutton" iconCls="icon-save" style="margin:0 10px">保存</a></w:notEqual>
</div>
<script type="text/javascript" src="<%=path %>/webadmin/product/productEdit.js"></script>
<script>
	$("#pedit_tabs").tabs({onSelect:function(title,index){
		if(index==1 && !detail_editor){
			detail_editor = keditor.create('[name="details_content"]', {
				allowFileManager : false,
				height:'300px',
				uploadJson : ctx+'/upload/fileupload?updir=info',
				items : [
					'fontname', 'fontsize', '|', 'textcolor', 'bgcolor', 'bold', 'italic', 'underline',
					'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
					'insertunorderedlist', '|', 'emoticons', 'image', 'link']
			});
		}else if(index==2 && !book_editor){
			book_editor = keditor.create('[name="book_content"]', {
				allowFileManager : false,
				height:'300px',
				uploadJson : ctx+'/upload/fileupload?updir=info',
				items : [
					'fontname', 'fontsize', '|', 'textcolor', 'bgcolor', 'bold', 'italic', 'underline',
					'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
					'insertunorderedlist', '|', 'emoticons', 'image', 'link']
			});
		}else if(index==3 && !aboutus_editor){
			aboutus_editor = keditor.create('[name="aboutus_content"]', {
				allowFileManager : false,
				height:'300px',
				uploadJson : ctx+'/upload/fileupload?updir=info',
				items : [
					'fontname', 'fontsize', '|', 'textcolor', 'bgcolor', 'bold', 'italic', 'underline',
					'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
					'insertunorderedlist', '|', 'emoticons', 'image', 'link']
			});
		}
		
	}})
	$w.doUrl(ctx+"/products/ProductPage@loadSaleattrs.page",{"bean.dataid":"<w:write bind="bean.photodataid"/>","bean.productid":"<w:write bind="bean.id"/>"},function(ret){
		var havemain=false;
		$(ret.attrs).each(function(){
			if(this.attrcodes=='0'){
				havemain=true;
				return false;
			}
		})
		var addmain=false;
		if(!havemain){
			//if(parseInt($getByName("sale_attrslen",$w.currWin).val())==0 && ret.attrs.length==0)addmain=true;
			//else pedit_addimgtr('',mainAttrid,ret.prophotos);
			if(ret.attrs.length==0)addmain=true;
		}
		
		if(addmain)pedit_addsaletr(mainAttrid,'0','','','','','',ret.prophotos);
		$(ret.attrs).each(function(){
			pedit_addsaletr(this.id,this.attrcodes,this.attrdesc,this.price_s,this.price,this.amount,this.djamount,this.photos,this.id);
		})
	})
	if($("#classtree2").length>0){
		window.setTimeout(function(){
			$("#classtree2").combotree("setValue","<%=classid%>");
			
		},1000);
	}
	function clscodechange(node){
		var nid=node.id;
		if(nid!=$getByName("inclassid",$w.currWin()).val())
			$w.reloadCurrWin(ctx+"/products/ProductPage@show.page?bean.id="+$getByName("bean.id",$w.currWin()).val()+"&bean.classid="+nid);
		
	}
	function synPhoto() {
        var h = "<div class='_photograph'>";
		$("#pedit_imgtb").find(".pl_upimgdiv").each(function () {
			var photo = $(this).find("img").attr("src");

			h+="<img src='"+photo+"' data-ke-src='"+photo+"'>";
        });
		h +="</div>";
        $(".ke-edit-iframe").contents().find(".ke-content ._photograph").remove();
        var detail_imgs = $(".ke-edit-iframe").contents().find(".ke-content>img");
        if( detail_imgs.length > 0 ){
            $(detail_imgs[0]).before(h);
		} else {
            var detail_pannels = $(".ke-edit-iframe").contents().find(".ke-content>div[style]");
            if( detail_pannels.length > 0 ){
                $(detail_pannels[0]).after(h);
			} else {
                $(".ke-edit-iframe").contents().find(".ke-content").prepend(h);
			}
		}
        var detail = $("[name='bean.details']").val();
        var before = detail.substring(0,detail.indexOf("<img"));
        var after = detail.substring(detail.indexOf("<img"),detail.length);
        var s = "<div class='_photograph'>";
        $("#pedit_imgtb").find(".pl_upimgdiv").each(function () {
            var photo = $(this).find("img").attr("src");

           s+="<img style='max-width:100%;' src='"+photo+"' />";
        });
        s +="</div>";
        detail= before + s + after;
        $("[name='bean.details']").val(detail);
    }
</script>